//
//  EmoticonTextAttachment.swift
//  表情键盘
//
//  Created by 晁岳山 on 15/10/25.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit
/// 自定义TextAttachment 原因：记录下表情的名字 发送给服务器
class EmoticonTextAttachment: NSTextAttachment {
    
    var emoticon: Emoticon
    
    func imageText(font: UIFont) -> NSAttributedString {
       image = UIImage(contentsOfFile: emoticon.imagePath)
        //textFiled中字体的大小 lineHeight
        let lineHeight = font.lineHeight
        bounds = CGRectMake(0, -4, lineHeight, lineHeight)
        let imageText = NSMutableAttributedString(attributedString:
            NSAttributedString(attachment: self))
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        return imageText
    }
    init(emoticon: Emoticon) {
        self.emoticon = emoticon
        super.init(data: nil, ofType: nil)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
